package com.order.model;  

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.jfinal.ext.plugin.tablebind.TableBind;
import com.jfinal.plugin.activerecord.Db;
import com.jfinal.plugin.activerecord.Model;
import com.jfinal.plugin.activerecord.Record;

/** 
 * @Title: CuisineDiet.java 
 * @Package com.order.model 
 * @Description: 菜系菜品主从表
 * @author LinBo
 * @date 2014-3-25 下午11:47:38 
 */

@TableBind(tableName="cuisine_dish", pkName="id")
public class CuisineDish extends Model<CuisineDish> {

	/** 
	 * @Fields serialVersionUID : 当前类可序列化的版本
	 */  
	private static final long serialVersionUID = -3047742912443895239L;
	public static final CuisineDish dao = new CuisineDish();
	
	/*由菜系id查找对应菜品*/
	public List<Dish> findDishByCuisineId(String cuisineId){
		String sql = "select d.* "
				+ " from dish d, cuisine_dish cd "
				+ " where cd.cuisine_id=? "
				+ " and cd.dish_id=d.id ";
		return Dish.dao.find(sql, cuisineId);
	}

	/** 
	* @Title: getCuisineDishMessageJson 
	* @描述: 获取菜品详情
	* @param cuisineId
	* @return   
	* Map<String,Object>    
	* @throws 
	*/ 
	public Map<String, Object> getCuisineDishMessageJson(int cuisineId) {
		String sql = "select d.id dish_id, d.sq, d.status, d.viewcount, d.name dish_name, "
				+ " d.info, d.price, d.image, d.last_updated_by, d.last_update_date, "
				+ " c.id cuisine_id, c.name cuisine_name "
				+ " 	from cuisine c, dish d, cuisine_dish cd "
				+ " 	where c.id = cd.cuisine_id "
				+ " 		and d.id = cd.dish_id ";
		List<Record> list = null;
		if(cuisineId != 0){
			sql += " 		and c.id = ? ";
			list = Db.find(sql, cuisineId);	
		}else{
			list = Db.find(sql);	
		}
		Map<String, Object> map = new HashMap<String, Object>();
		map.put("Rows", list);
		return map;
	}

	
}
  